import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes.js'

import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({showSpinner:false})

Vue.use(VueRouter)



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


// 全局前置守卫
router.beforeEach((to, from, next) => {
  NProgress.start()
  // 动态修改网页标题
  document.title = to.meta && to.meta.title || '饿了么';
  if (to.path == '/Order' || to.path == '/mine') {
    // if (!token) {
    //   next()
    // } else {
      next('/LoGin')
    // }
  } else {
    next()
  }
  
})



// 全局后置守卫
router.afterEach((to,from) => {
  NProgress.done()
})

export default router
